package cn.e2win.biz.tools;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;

public class FileHelper {
	 public String reader(String templatePath) throws IOException{
         File file=new File(templatePath);
         if(!file.exists()||file.isDirectory())
             throw new FileNotFoundException();
         BufferedReader br=new BufferedReader(new FileReader(file));
         String temp=null;
         StringBuffer sb=new StringBuffer();
         temp=br.readLine();
         while(temp!=null){
             sb.append(temp+"\r\n");
             temp=br.readLine();
         }
         return sb.toString();
     }
	 
	 public void writer(String fileContent, String destinationPath) throws IOException{
         File file=new File(destinationPath);
         if(file.exists()){
             file.delete();
         }else{
            	 file.mkdirs();
            	 file.delete();
            	 file.createNewFile();
         }
         
         
         FileOutputStream out=new FileOutputStream(file,true);        
         
         StringBuffer sb=new StringBuffer(fileContent);
         out.write(sb.toString().getBytes("utf-8"));
             
         out.close();
     }
	 
	 
}
